﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication5.Admin
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        private DataClassesOnlineCollegeManagementDataContext dc = new DataClassesOnlineCollegeManagementDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.DataList1.DataSource = dc.lists.ToList();
                this.DataList1.DataBind();
            }
        }

        protected void buttoninsert_click(object sender, EventArgs e)
        {
            list lii = new list();
            lii.idlist = Convert.ToInt32(this.textboxidlist.Text);
            lii.tenlist = this.textboxtenlist.Text;
            this.dc.lists.InsertOnSubmit(lii);
            this.dc.SubmitChanges();

            this.DataList1.DataSource = dc.lists.ToList();
            this.DataList1.DataBind();
            this.textboxidlist.Text = null;
            this.textboxtenlist.Text = null;
        }
        protected void edit_click(object sender, EventArgs e)
        {
            try
            {
              
                list dm = dc.lists.Single(a => a.idlist == Convert.ToInt32(this.textboxidlist.Text));
                dm.tenlist = this.textboxtenlist.Text;
                dc.SubmitChanges();
                Response.Redirect("Home.aspx");
            }
            catch
            {
                this.Labelmessage.Text = "Update Error";
            }

            this.DataList1.DataSource = dc.lists.ToList();
            this.DataList1.DataBind();
        }
        protected void LinkButtondelete_click(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            HiddenField hd = (HiddenField)lb.FindControl("HiddenFieldidlist");
            list lii = this.dc.lists.Single(a=>a.idlist == Convert.ToInt32(hd.Value));
            this.dc.lists.DeleteOnSubmit(lii);
            this.dc.SubmitChanges();

            this.DataList1.DataSource = dc.lists.ToList();
            this.DataList1.DataBind();
        }
       
    }
}